package com.nondo.dean.auth.common;

import com.nondo.dean.auth.common.bean.*;
import com.nondo.dean.auth.domain.*;

public final class BusinessUtils {

    public static final String OPERA_ADD = "add";
    public static final String OPERA_REMOVE = "remove";

    public static User toUser(UserItem item) {
        User key = new User();
        key.setName(item.getName());
        key.setUsername(item.getUsername());
        key.setEmail(item.getEmail());
        return key;
    }

    public static Company toCompany(CompanyItem item) {
        Company role = new Company();
        role.setId(item.getId());
        role.setName(item.getName());
        role.setParentName(item.getParentName());
        role.setParentId(item.getParentId());
        role.setDelFlag(Role.DEL_FLAG_NORMAL);
        return role;
    }

    public static Office toOffice(OfficeItem item) {
        if (item == null) {
            return null;
        }
        Office role = new Office();
        role.setId(item.getId());
        role.setName(item.getName());
        role.setCompanyId(item.getCompanyId());
        role.setCompanyName(item.getCompanyName());
        role.setParentId(item.getParentId());
        role.setDelFlag(Role.DEL_FLAG_NORMAL);
        return role;
    }

    public static Position toPosition(PositionItem item) {
        if (item == null) {
            return null;
        }
        Position role = new Position();
        role.setId(item.getId());
        role.setName(item.getName());
        role.setCompanyId(item.getCompanyId());
        role.setCompanyName(item.getCompanyName());
        role.setDelFlag(Role.DEL_FLAG_NORMAL);
        return role;
    }

    public static UserRoleKey toUserRoleKey(Long roleId, Long userId) {
        UserRoleKey key = new UserRoleKey();
        key.setRoleId(roleId);
        key.setUserId(userId);
        key.setDelFlag(Role.DEL_FLAG_NORMAL);
        return key;
    }

    public static RoleMenuKey toRoleMenuKey(Long roleId, Long menuId) {
        RoleMenuKey key = new RoleMenuKey();
        key.setRoleId(roleId);
        key.setMenuId(menuId);
        key.setDelFlag(Role.DEL_FLAG_NORMAL);
        return key;
    }

    public static RoleAuthorityKey toRoleAuthorityKey(Long roleId, Long authorityId) {
        RoleAuthorityKey key = new RoleAuthorityKey();
        key.setRoleId(roleId);
        key.setAuthorityId(authorityId);
        key.setDelFlag(Role.DEL_FLAG_NORMAL);
        return key;
    }

    public static App toApp(AppItem appItem) {
        App role = new App();
        role.setAppKey(appItem.getAppKey());
        role.setAppName(appItem.getAppName());
        role.setNotUpdate(appItem.getNotUpdate());
        return role;
    }

    public static Role toRole(RoleItem roleItem) {
        Role role = new Role();
        role.setId(roleItem.getId());
        role.setName(roleItem.getName());
        role.setCode(roleItem.getCode());
        role.setDelFlag(Role.DEL_FLAG_NORMAL);
        return role;
    }

    public static Authority toAuthority(AuthorityItem authorityItem) {
        Authority authority = new Authority();
        authority.setId(authorityItem.getId());
        authority.setName(authorityItem.getName());
        authority.setTableName(authorityItem.getTableName());
        authority.setGlobal(authorityItem.getGlobal());
        authority.setDomainForce(authorityItem.getDomainForce());
        return authority;
    }

    public static Menu toMenu(MenuItem menuItem) {
        if (menuItem == null) {
            return null;
        }
        Menu menu = new Menu();
        menu.setId(menuItem.getId());
        menu.setCode(menuItem.getCode());
        menu.setAction(menuItem.getAction());
        menu.setHide(menuItem.getHide());
        menu.setIcon(menuItem.getIcon());
        menu.setName(menuItem.getName());
        menu.setParentId(menuItem.getParentId());
        menu.setSequence(menuItem.getSequence());
        menu.setParentIds(menuItem.getParentIds());
        return menu;
    }

}
